package com.lenovo.agricultureServer.http.action;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import com.lenovo.agricultureServer.ServerApp;

public class SetConfigAction extends BaseAction 
{
	public static final String TAG = "setConfig";
	
	private Context context;
	public SetConfigAction(Context context)
	{
		this.context = context;
	}
	
	@Override
	protected String jasonPorcess(String param) 
	{
		JSONObject jsonResponse = new JSONObject();
		try 
		{
			// 处理设置告警范围请求
			ServerApp app = (ServerApp)context;
			JSONObject jsonRequest = new JSONObject(param);
			
			if(jsonRequest.has("minAirTemperature")){
				app.setMinAirTemperature(jsonRequest.getInt("minAirTemperature"));
			}
			if(jsonRequest.has("maxAirTemperature")){
				app.setMaxAirTemperature(jsonRequest.getInt("maxAirTemperature"));
			}
			if(jsonRequest.has("minAirHumidity")){
				app.setMinAirHumidity(jsonRequest.getInt("minAirHumidity"));
			}
			if(jsonRequest.has("maxAirHumidity")){
				app.setMaxAirHumidity(jsonRequest.getInt("maxAirHumidity"));
			}
			
			if(jsonRequest.has("minSoilTemperature")){
				app.setMinEarthTemperature(jsonRequest.getInt("minSoilTemperature"));
			}
			if(jsonRequest.has("maxSoilTemperature")){
				app.setMaxEarthTemperature(jsonRequest.getInt("maxSoilTemperature"));
			}
			if(jsonRequest.has("minSoilHumidity")){
				app.setMinEarthHumidity(jsonRequest.getInt("minSoilHumidity"));
			}
			if(jsonRequest.has("maxSoilHumidity")){
				app.setMaxEarthHumidity(jsonRequest.getInt("maxSoilHumidity"));
			}
			
			if(jsonRequest.has("minLight")){
				app.setMinLight(jsonRequest.getInt("minLight"));
			}
			if(jsonRequest.has("maxLight")){
				app.setMaxLight(jsonRequest.getInt("maxLight"));
			}
			if(jsonRequest.has("minCo2")){
				app.setMinCo2(jsonRequest.getInt("minCo2"));
			}
			if(jsonRequest.has("maxCo2")){
				app.setMaxCo2(jsonRequest.getInt("maxCo2"));
			}
			
			if(jsonRequest.has("maxPM25")){
				app.setMaxPm25(jsonRequest.getInt("maxPM25"));
			}
			if(jsonRequest.has("controlAuto")){
				app.setControlAuto(jsonRequest.getInt("controlAuto"));
			}
			
			jsonResponse.put("result", "ok");
			return jsonResponse.toString();
		} 
		catch (JSONException e) 
		{
			e.printStackTrace();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected String soapPorcess(String param) {
		//TODO
		return "";
	}

}
